﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Practices.Unity;

using Farmacia.BussinessLogic;



namespace Farmacia.net.Compras.Proveedor
{
    public partial class frmRegistrarProveedor : BasePage<frmRegistrarProveedor>
    {
        [Dependency]
        public iProveedorBL ProveedorBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {    
            
            var opc = Request.QueryString["acc"];

            if (opc != string.Empty) 
            {
                if (opc == "ver")
                {
                    FormView1.ChangeMode(FormViewMode.ReadOnly);
                }
                if (opc == "nuevo")
                {
                    FormView1.ChangeMode(FormViewMode.Insert);
                }
                if (opc == "editar")
                {
                    FormView1.ChangeMode(FormViewMode.Edit);
                }
                if (opc == "eliminar")
                {
                    odsProveedor.DataObjectTypeName = "";
                    odsProveedor.Delete();
                    Response.Redirect("frmBuscarProveedor.aspx");
                }    
            }
        }

         protected void odsProveedor_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = ProveedorBL;
        }

         protected void odsProveedor_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
         {
             if (e.Exception != null)
             {
                 if (e.Exception.InnerException != null)
                 {
                     Response.Redirect("frmBuscarProveedor.aspx?msg=" + e.Exception.InnerException.Message);
                 }
             }
             else
             {
                 Response.Redirect("frmBuscarProveedor.aspx");
             }
         }

         protected void odsProveedor_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
         {
             Response.Redirect("frmBuscarProveedor.aspx");
         }

         protected void odsProveedor_Updated(object sender, ObjectDataSourceStatusEventArgs e)
         {
             Response.Redirect("frmBuscarProveedor.aspx");
         }


    }
}